
<div class="form-horizontal mt-1">
    <div class="show-field form-group row">
        <div class="col-sm-2 control-label">
            <span>短链:</span>
        </div>

        <div class="col-sm-8">
            <div class="box box-solid box-default no-margin box-show">
                <div class="box-body link-content">{{ $link }}&nbsp;</div>
            </div>
        </div>
    </div>

    <div class="show-field form-group row">
        <div class="col-sm-2 control-label">
            <span></span>
        </div>

        <div class="col-sm-8">
            <div class="box-body">
                @if($link)
                    <button class="btn btn-primary btn-generate" data-id="{{ $id }}">重新生成</button>
                @else
                    <button class="btn btn-primary btn-generate" data-id="{{ $id }}">生成</button>
                @endif
            </div>
        </div>
    </div>

    <div class="clearfix"></div>
</div>

<script>
    $('.btn-generate').click(function () {
        Dcat.loading();

        $.ajax({
            url: "{{ admin_route('diy_form_generate_short_link') }}",
            data: {id: $(this).data('id')},
            type: "POST",
            dataType: 'JSON',
            success: function (res) {
                Dcat.loading(false);
                if (!res.status) {
                    Dcat.error(res.msg);
                } else {
                    $('.link-content').html(res.data)
                    Dcat.success(res.msg);
                }
            }
        })
    })
</script>

